﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Apollo
{
    public class ActionSubscription
    {
        public const int DEFAULT_PRIORITY = 10;

        public ActionSubscription(IModule module, bool isAllowedForCurrentUser) : this(module, isAllowedForCurrentUser, ActionHandlingType.Passive, DEFAULT_PRIORITY) { }

        public ActionSubscription(IModule module, bool isAllowedForCurrentUser, ActionHandlingType handlingType, int priority)
        {
            this.Priority = priority;
            this.IsAllowedForCurrentUser = isAllowedForCurrentUser;
            this.HandlingType = handlingType;
            this.Module = module;
            this.CallerType = ActionSubscriptionCaller.Module;
        }

        public ActionSubscription(ActionHandlerContainer handlerContainer) {
            this.Priority = handlerContainer.Priority;
            this.IsAllowedForCurrentUser = true;
            this.HandlingType = handlerContainer.HandlingType;
            this.Handler = handlerContainer.Handler;
            this.CallerType = ActionSubscriptionCaller.StaticMethod;
        }

        /// <summary>
        /// Is the order in which the operations will be executed. The lowest will be treated first. 
        /// Default is 10.
        /// </summary>
        public int Priority { get; private set; }

        public ActionHandlingType HandlingType { get; private set; }

        /// <summary>
        /// True if the CurrentUser can do the action
        /// </summary>
        public bool IsAllowedForCurrentUser { get; private set; }

        public IModule Module { get; private set; }

        public ActionHandler Handler { get; private set; }

        public ActionSubscriptionCaller CallerType { get; private set; }
    }

    public class EditActionSubscription : ActionSubscription {
        public Entity Entity { get; set; }
        public EntityEdit Edit { get; set; }

        public EditActionSubscription(IModule module, bool isAllowedForCurrentUser, ActionHandlingType handlingType, int priority) : base(module, isAllowedForCurrentUser, handlingType, priority)
        { }
    }

    public enum ActionSubscriptionCaller
    { 
        Module = 0,
        StaticMethod = 1
    }
}
